package insat.challenge;

import insat.challenge.metier.Place;
import insat.challenge.metier.PlaceCategory;

import java.util.List;
import java.util.Vector;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

public class CategoryInfoActivity extends DashboardActivity implements OnItemClickListener {
	private TextView categoryname;
	
	ListView listView;
	private String category_name;
	private String category_id;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.categoryinfo);
		categoryname = (TextView) findViewById(R.id.categoryname);
		

		Intent intent = getIntent();

		Bundle b = intent.getBundleExtra("android.intent.extra.INTENT");
		Log.i("name of the category", b.getString("name"));
		if (intent != null) {

			if (b == null)
				categoryname.setText("bad bundle?");

			else
				{categoryname.setText(b.getString("name"));
				category_name= b.getString("name");
				category_id = b.getString("id");
				}
				

		}
		
		
		
		
		listView = (ListView)findViewById(R.id.listView_places);
		setBaseAdapter();
		
		
	}
	
	
	private void setBaseAdapter() {
		PlaceCategory placeCategory =new PlaceCategory();
		placeCategory.setName(category_name);
		placeCategory.setId(category_id);
		Place place = new Place();
		Vector<Place> placeofthiscategory =place.searchPlaces1(placeCategory, place.getPlaces());
		ArrayAdapter<Place> adapter = new ArrayAdapter<Place>(this,
				android.R.layout.simple_list_item_1, placeofthiscategory);
		listView.setAdapter(adapter);
		listView.setOnItemClickListener(this);

	}

	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		Place place = (Place) arg0.getItemAtPosition(arg2);
		Log.i("adrees", place.getAdress());

	}
	
	
}
